import 'package:flutter/material.dart';
import 'package:top_foundation/component/component.dart';
import 'package:top_foundation/top_foundation.dart';
import 'package:whale/helper/utils/util.dart';

class RaidersGridView extends StatelessWidget {
  const RaidersGridView({
    super.key,
    required this.itemBuilder,
    required this.centerChild,
    this.spacing = 0,
    this.runSpacing = 0,
  });
  final double spacing;
  final double runSpacing;
  final Widget Function(int index) itemBuilder;
  final Widget centerChild;

  Widget _item(int index) {
    return SizedBox(
      width: 51.r,
      height: 51.r,
      child: itemBuilder(index),
    );
  }

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, cons) {
      var itemSize1 = 51.r;
      var spacing = ((cons.biggest.width - itemSize1 * 6) / 5).floorToDouble();
      var runSpacing = ((cons.biggest.height - (51.r * 5)) / 4).floorToDouble();

      return Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: List.generate(
              6,
              (index) => _item(index),
            ),
          ),
          SizedBox(height: runSpacing),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SeparatorColumn(
                children: List.generate(3, (index) {
                  var i = index * 2 + 6;
                  return _item(i);
                }),
                separatorBuilder: (index) => SizedBox(height: runSpacing),
              ),
              SizedBox(
                width: itemSize1 * 4 + spacing * 3,
                height: itemSize1 * 3 + runSpacing * 2,
                child: centerChild,
              ),
              SeparatorColumn(
                children: List.generate(3, (index) {
                  var i = (index * 2 + 1) + 6;
                  return _item(i);
                }),
                separatorBuilder: (index) => SizedBox(height: runSpacing),
              ),
            ],
          ),
          SizedBox(height: runSpacing),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: List.generate(
              6,
              (index) => _item(index + 12),
            ),
          ),
        ],
      );
    });
  }
}
